﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using StairsModuleAndEdit.StairsEdit.Common;
using StairsModuleAndEdit.StairsEdit.DataDefine;

namespace StairsModuleAndEdit.StairsEdit.Managers
{
	internal class PairingStairsCls
	{
		public PairingStairsCls(ExternalCommandData commandData, List<Stairs> arStairs)
		{
			this.m_commandData = commandData;
			this.m_doc = this.m_commandData.Application.ActiveUIDocument.Document;
		}

		public void PairingStairs(out List<PairsStairs> arPairsStairs, ref List<Stairs> arStairs)
		{
			arPairsStairs = new List<PairsStairs>();
			for (int i = 0; i < arStairs.Count; i++)
			{
				Stairs stairs = arStairs[i];
				if (stairs != null)
				{
					ElementId ArchStairsId = null;
					if (StairsXDataManager.ReadArchStairsId(stairs, ref ArchStairsId))
					{
						int num = arStairs.FindIndex((Stairs s) => s != null && s.Id == ArchStairsId);
						if (num != -1)
						{
							Stairs val = this.m_doc.GetElement(ArchStairsId) as Stairs;
							PairsStairs item = new PairsStairs(val, stairs);
							arPairsStairs.Add(item);
							arStairs[num] = null;
							arStairs[i] = null;
						}
					}
				}
			}
			for (int j = arStairs.Count - 1; j >= 0; j--)
			{
				if (arStairs[j] == null)
				{
					arStairs.RemoveAt(j);
				}
			}
		}

		private ExternalCommandData m_commandData;

		private Document m_doc;
	}
}
